<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="微信id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wxid">
              <a-input v-model="model.wxid" placeholder="请输入微信id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="微信群中昵称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nickname">
              <a-input v-model="model.nickname" placeholder="请输入微信群中昵称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="邀请人的微信" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invitedWxid">
              <a-input v-model="model.invitedWxid" placeholder="请输入邀请人的微信"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="进群时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="entryTime">
              <j-date placeholder="请选择进群时间"  v-model="model.entryTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="群组id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="groupId">
              <a-input v-model="model.groupId" placeholder="请输入群组id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="微信头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avatar">
              <a-input v-model="model.avatar" placeholder="请输入微信头像"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="money">
              <a-input-number v-model="model.money" placeholder="请输入金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所以金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalMoney">
              <a-input-number v-model="model.totalMoney" placeholder="请输入所以金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="签到时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signinTime">
              <j-date placeholder="请选择签到时间"  v-model="model.signinTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="签到天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dayCount">
              <a-input-number v-model="model.dayCount" placeholder="请输入签到天数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="冻结金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="freezeMoney">
              <a-input-number v-model="model.freezeMoney" placeholder="请输入冻结金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
              <a-input-number v-model="model.type" placeholder="请输入类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否开启" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isEnable">
              <a-input-number v-model="model.isEnable" placeholder="请输入是否开启" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手气最佳时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="haveTheBestLuck">
              <j-date placeholder="请选择手气最佳时间"  v-model="model.haveTheBestLuck" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="进群是否通知" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isNotification">
              <j-dict-select-tag type="list" v-model="model.isNotification" dictCode="IsNotification" placeholder="请选择进群是否通知" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="佣金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="commission">
              <a-input-number v-model="model.commission" placeholder="请输入佣金" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'TbGroupMemberForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/coupon/tbGroupMember/add",
          edit: "/coupon/tbGroupMember/edit",
          queryById: "/coupon/tbGroupMember/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>